﻿
#region 程序集引用区
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SubSonic.DataProviders;
using SubSonic.Extensions;
using System.Linq.Expressions;
using SubSonic.Schema;
using System.Collections;
using SubSonic;
using SubSonic.Repository;
using System.ComponentModel;
using System.Data.Common;
using SubSonic.Query;
using System.Xml;
using System.Xml.Serialization;
using System.Reflection;
#endregion

namespace eTerm.PlugIn.TicketImport{
    
    /// <summary>
    /// 文 件 名: SysUser.cs
    /// CLR版本 : v2.0.50727
    /// 作   者 : lijun.hu
    /// 版    权: Copyright @2011 lijun.hu(FORCEN HU) 
    /// 电子邮箱：lijun.hu@shinsoft.net
    /// 说    明: 用户表
    /// 生成日期: 2013年7月29日
    /// </summary>
    [Serializable]
    public partial class SysUser:IActiveRecord{
        
        #region 变量定义
        private bool isLoaded=false;
        private bool isNew=false;
        private List<IColumn> dirtyColumns;
        IRepository< SysUser > _repo;
        ITable tbl;
        private static IQuerySurface _db;
        #endregion
        
        #region 构造函数
        /// <summary>
        /// 初始化一个新实例 <see cref="SysUser"/>.
        /// <param name="dbProvider">采用注入式数据库配置初始化.</param>
        /// </summary>
        public SysUser(IQuerySurface dbProvider){
            if (dbProvider != null) {
                _db = dbProvider;
                Init();
            }
        }
        
        /// <summary>
        /// 初始化一个新实例 <see cref="SysUser"/>.
        /// </summary>
        public SysUser(){
            if(_db==null)
                _db = Context.Instance.DbProvider;
            if(_db!=null)
                Init();
        }
        
        
        /// <summary>
        /// 实例内部初始化逻辑.
        /// </summary>
        void Init(){
            _repo = new SubSonicRepository< SysUser >(_db);
            tbl=_repo.GetTable();
            dirtyColumns=new List<IColumn>();
            SetIsNew(true);     
        }
        #endregion
        
        #region 生成IRepository
        internal static IRepository< SysUser > GetRepo(){
            if (_db == null)
                _db = Context.Instance.DbProvider;
            IRepository< SysUser > _repo;
            _repo = new SubSonicRepository< SysUser >(_db);
            return _repo;         
        }       
        #endregion
        
        #region SysUser属性列表
        System.Int32 m_UserId;
        /// <summary>
        /// 未定义
        ///</summary>
        [XmlAttribute()]
        public System.Int32  UserId
        {
            get { return m_UserId; }
            set
            {
                if(m_UserId!=value)
                {
                    m_UserId=value;
                    var col=tbl.Columns.FirstOrDefault(x=>x.PropertyName.ToLower()=="UserId".ToLower());
                    if(col!=null){
                        if(!dirtyColumns.Any(x=>x.Name.ToLower()==col.Name.ToLower()) && isLoaded){
                            dirtyColumns.Add(col);
                        }
                    }
                }
            }
        }
        
        System.String m_CompanyCode;
        /// <summary>
        /// 未定义
        ///</summary>
        [XmlAttribute()]
        public System.String  CompanyCode
        {
            get { return m_CompanyCode; }
            set
            {
                if(m_CompanyCode!=value)
                {
                    m_CompanyCode=value;
                    var col=tbl.Columns.FirstOrDefault(x=>x.PropertyName.ToLower()=="CompanyCode".ToLower());
                    if(col!=null){
                        if(!dirtyColumns.Any(x=>x.Name.ToLower()==col.Name.ToLower()) && isLoaded){
                            dirtyColumns.Add(col);
                        }
                    }
                }
            }
        }
        
        System.String m_UserNo;
        /// <summary>
        /// 未定义
        ///</summary>
        [XmlAttribute()]
        public System.String  UserNo
        {
            get { return m_UserNo; }
            set
            {
                if(m_UserNo!=value)
                {
                    m_UserNo=value;
                    var col=tbl.Columns.FirstOrDefault(x=>x.PropertyName.ToLower()=="UserNo".ToLower());
                    if(col!=null){
                        if(!dirtyColumns.Any(x=>x.Name.ToLower()==col.Name.ToLower()) && isLoaded){
                            dirtyColumns.Add(col);
                        }
                    }
                }
            }
        }
        
        System.String m_DisplayName;
        /// <summary>
        /// 未定义
        ///</summary>
        [XmlAttribute()]
        public System.String  DisplayName
        {
            get { return m_DisplayName; }
            set
            {
                if(m_DisplayName!=value)
                {
                    m_DisplayName=value;
                    var col=tbl.Columns.FirstOrDefault(x=>x.PropertyName.ToLower()=="DisplayName".ToLower());
                    if(col!=null){
                        if(!dirtyColumns.Any(x=>x.Name.ToLower()==col.Name.ToLower()) && isLoaded){
                            dirtyColumns.Add(col);
                        }
                    }
                }
            }
        }
        
        System.String m_Password;
        /// <summary>
        /// 未定义
        ///</summary>
        [XmlAttribute()]
        public System.String  Password
        {
            get { return m_Password; }
            set
            {
                if(m_Password!=value)
                {
                    m_Password=value;
                    var col=tbl.Columns.FirstOrDefault(x=>x.PropertyName.ToLower()=="Password".ToLower());
                    if(col!=null){
                        if(!dirtyColumns.Any(x=>x.Name.ToLower()==col.Name.ToLower()) && isLoaded){
                            dirtyColumns.Add(col);
                        }
                    }
                }
            }
        }
        
        System.String m_Email;
        /// <summary>
        /// 未定义
        ///</summary>
        [XmlAttribute()]
        public System.String  Email
        {
            get { return m_Email; }
            set
            {
                if(m_Email!=value)
                {
                    m_Email=value;
                    var col=tbl.Columns.FirstOrDefault(x=>x.PropertyName.ToLower()=="Email".ToLower());
                    if(col!=null){
                        if(!dirtyColumns.Any(x=>x.Name.ToLower()==col.Name.ToLower()) && isLoaded){
                            dirtyColumns.Add(col);
                        }
                    }
                }
            }
        }
        
        System.String m_Mobile;
        /// <summary>
        /// 未定义
        ///</summary>
        [XmlAttribute()]
        public System.String  Mobile
        {
            get { return m_Mobile; }
            set
            {
                if(m_Mobile!=value)
                {
                    m_Mobile=value;
                    var col=tbl.Columns.FirstOrDefault(x=>x.PropertyName.ToLower()=="Mobile".ToLower());
                    if(col!=null){
                        if(!dirtyColumns.Any(x=>x.Name.ToLower()==col.Name.ToLower()) && isLoaded){
                            dirtyColumns.Add(col);
                        }
                    }
                }
            }
        }
        
        System.String m_Description;
        /// <summary>
        /// 未定义
        ///</summary>
        [XmlAttribute()]
        public System.String  Description
        {
            get { return m_Description; }
            set
            {
                if(m_Description!=value)
                {
                    m_Description=value;
                    var col=tbl.Columns.FirstOrDefault(x=>x.PropertyName.ToLower()=="Description".ToLower());
                    if(col!=null){
                        if(!dirtyColumns.Any(x=>x.Name.ToLower()==col.Name.ToLower()) && isLoaded){
                            dirtyColumns.Add(col);
                        }
                    }
                }
            }
        }
        
        System.Int32? m_ParentId;
        /// <summary>
        /// 未定义
        ///</summary>
        [XmlAttribute()]
        public System.Int32?  ParentId
        {
            get { return m_ParentId; }
            set
            {
                if(m_ParentId!=value)
                {
                    m_ParentId=value;
                    var col=tbl.Columns.FirstOrDefault(x=>x.PropertyName.ToLower()=="ParentId".ToLower());
                    if(col!=null){
                        if(!dirtyColumns.Any(x=>x.Name.ToLower()==col.Name.ToLower()) && isLoaded){
                            dirtyColumns.Add(col);
                        }
                    }
                }
            }
        }
        
        #endregion
        
        #region 修改属性
        /// <summary>
        /// 设置该记录为新数据(供Save方法判断为Insert或Update)
        ///</summary>
        public void SetIsNew(bool isNew){
            this.isNew=isNew;
            this.isLoaded = !isNew;
        }
        
        /// <summary>
        /// 设置该记录是否从数据读取
        ///</summary>
        public void SetIsLoaded(bool isLoaded){
            this.isLoaded=isLoaded;
            this.isNew = !isLoaded;
        }
        
        /// <summary>
        /// 设置数据访问接口
        ///</summary>
        public void SetDbProvider(IQuerySurface dbProvider){
            _db=dbProvider;
            Init();
        }
        #endregion
        
        #region 获取属性
        /// <summary>
        /// 获取该记录是否从数据读取
        ///</summary>
        public bool IsLoaded(){
            return isLoaded;
        }
        
        /// <summary>
        /// 实体中是否含有可更新属性
        ///</summary>
        public bool IsDirty(){
            return dirtyColumns.Count>0;
        }
        
        /// <summary>
        /// 实体是否为新实体
        ///</summary>
        public bool IsNew(){
            return isNew;
        }
        
        /// <summary>
        /// 获取所有可更新属性集合
        ///</summary>
        public List<IColumn> GetDirtyColumns (){
            return dirtyColumns;
        }
        
        /// <summary>
        /// 获取Mapping表所有数据列
        ///</summary>
        [Browsable(false)]
        [XmlIgnore()]
        public IList<IColumn> Columns{
            get{
                return tbl.Columns;
            }
        }
        #endregion    
        
        #region 主键相关
        /// <summary>
        /// 获取表主键（不能使用组合主键）
        ///</summary>
        public string KeyName()
        {
            return "UserId";
        }

        /// <summary>
        /// 获取表主键值
        ///</summary>
        public object KeyValue()
        {
            return this.UserId;
        }
        
        /// <summary>
        /// 设置主键值
        ///</summary>
        public void SetKeyValue(object value) {
            if (value != null && value!=DBNull.Value) {
                var settable = value.ChangeTypeTo< System.Int32 >();
                this.GetType().GetProperty(this.KeyName()).SetValue(this, settable, null);
            }
        }
        
        /// <summary>
        /// 主键ToString()
        ///</summary>
        public override string ToString(){
            return this.UserId.ToString();
        }
        
        
        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
        /// </returns>
        public override int GetHashCode() {
            return base.GetHashCode();
        }

        
        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        /// 	<c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">
        /// The <paramref name="obj"/> parameter is null.
        /// </exception>
        public override bool Equals(object obj){
            if(obj.GetType()==typeof(SysUser)){
                SysUser compare=(SysUser)obj;
                return compare.KeyValue()==this.KeyValue();
            }else{
                return base.Equals(obj);
            }
        }

        /// <summary>
        /// Descriptors the value.
        /// </summary>
        /// <returns></returns>
        public string DescriptorValue()
        {
            return this.UserId.ToString();
        }
        
        /// <summary>
        /// Descriptors the column.
        /// </summary>
        /// <returns></returns>
        public string DescriptorColumn() {
            return "UserID";
        }
        
        /// <summary>
        /// Gets the key column.
        /// </summary>
        /// <returns></returns>
        public static string GetKeyColumn()
        {
            return "UserID";
        }   
        
        /// <summary>
        /// Gets the descriptor column.
        /// </summary>
        /// <returns></returns>        
        public static string GetDescriptorColumn()
        {
            return "UserID";
        }
        #endregion
        
        #region 手动设置更新属性
        /// <summary>
        /// 手动设置更新属性.
        /// <param name="property">需要更新至数据库的属性.</param>
        /// </summary>
        public void SetUpdateProperty(IColumn property) {
            if ( !property.IsPrimaryKey&& tbl.Columns.Count(x => x.Name.ToLower() == property.Name.ToLower()) > 0 && dirtyColumns.Any(x => x.Name.ToLower() == property.Name.ToLower())){
                dirtyColumns.Add(property);
                isLoaded = true;
            }
        }
        
        

        /// <summary>
        /// 手动设置更新属性
        /// <param name="properties">需要更新至数据库的属性列表</param>
        /// </summary>
        public void SetUpdateProperty(IList<IColumn> properties)
        {
            properties.ToList().ForEach(l => {
                SetUpdateProperty(l);
            });
        }
        #endregion
        
        #region DbCommand相关
        public DbCommand GetUpdateCommand() {
            return this.ToUpdateQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetInsertCommand() {
            return this.ToInsertQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        
        public DbCommand GetDeleteCommand() {
            return this.ToDeleteQuery(_db.Provider).GetCommand().ToDbCommand();
        }
        #endregion 
        
        #region 删除方法
        /// <summary>
        /// 实例数据Mapping自己删除.
        /// <param name="provider">数据.</param>
        /// </summary>
        public void Delete(IDataProvider provider) {
            _repo.Delete(KeyValue());
        }
        
        /// <summary>
        /// 实例数据Mapping自己删除.
        /// </summary>
        public void Delete() {
            Delete(_db.Provider);
        }
        
        /// <summary>
        /// 实例数据Mapping自己删除.
        /// </summary>
        public void Delete(Expression<Func< SysUser, bool>> expression) {
            var repo = GetRepo();
            repo.DeleteMany(expression);
        }
        #endregion
        
        #region 修改方法
        public void Update(){
            Update(_db.Provider);
        }
        
        public void Update(IDataProvider provider){
            if(this.dirtyColumns.Count>0)
                _repo.Update(this,provider);
       }
    
        public void Add(){
            Add(_db.Provider);
        }
       
        public void Add(IDataProvider provider){
            var key=(System.Int32)KeyValue();
            //if(key==(int)0)
            //{
                var newKey=_repo.Add(this,provider);
                this.SetKeyValue(newKey);
            //}else{
            //    _repo.Add(this,provider);
            //}
            SetIsNew(false);
        }
        
        
        public void Save() {
            Save(_db.Provider);
        }      
        
        public void Save(IDataProvider provider) {
            if (isNew) {
                Add(provider);
            } else {
                Update(provider);
            }
            
        }
        
        /*
        public void Save(SysUser Refer) {
            SysUser dbClass = FirstOrDefault(l => l.UserId == Refer.UserId);
                dbClass.CompanyCode = Refer.CompanyCode;
                dbClass.UserNo = Refer.UserNo;
                dbClass.DisplayName = Refer.DisplayName;
                dbClass.Password = Refer.Password;
                dbClass.Email = Refer.Email;
                dbClass.Mobile = Refer.Mobile;
                dbClass.Description = Refer.Description;
                dbClass.ParentId = Refer.ParentId;
            dbClass.Save();
        }
        */


        public void Load(IDataReader rdr) {
            Load(rdr, true);
        }
        public void Load(IDataReader rdr, bool closeReader) {
            if (rdr.Read()) {

                try {
                    rdr.Load(this);
                    SetIsNew(false);
                    SetIsLoaded(true);
                } catch {
                    SetIsLoaded(false);
                    throw;
                }
            }else{
                SetIsLoaded(false);
            }

            if (closeReader)
                rdr.Dispose();
        }
        
        #endregion
        
        #region 静态方法
        /// <summary>
        /// 按条件获取 "用户表" 单实体 .
        /// </summary>
        /// <param name="expression">条件表达式.</param>
        /// <returns></returns>
        public static SysUser FirstOrDefault(Expression<Func< SysUser, bool>> expression) {
            var repo = GetRepo();
            var results = repo.Find(expression);
            SysUser single = null;
            /*if (results.Count() > 0) */
            {
                single = results.FirstOrDefault();
                if(single!=null){
                    single.SetIsLoaded(true);
                    single.SetIsNew(false);
                }
            }
            return single;
        }      
        

        /// <summary>
        /// 查询所有 "用户表" 数据
        /// </summary>
        /// <returns></returns>
        public static IQueryable<SysUser> All() {
            return GetRepo().GetAll();
        }

        /// <summary>
        /// 按主键加载唯一实例.
        /// </summary>
        /// <param name="key">主键值.</param>
        /// <returns></returns>
        public static SysUser FirstOrDefault(object key) {
            return GetRepo().GetByKey(key);
        }


        /// <summary>
        /// 查询分页数据.
        /// </summary>
        /// <param name="sortBy">排序表达式</param>
        /// <param name="pageIndex">页次.</param>
        /// <param name="pageSize">页面大小</param>
        /// <returns></returns>
        public static PagedList<SysUser> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }


        /// <summary>
        /// 查询分页数据.
        /// </summary>
        /// <param name="pageIndex">页次.</param>
        /// <param name="pageSize">页面大小</param>
        /// <returns></returns>
        public static PagedList<SysUser> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);

        }
        
        /// <summary>
        /// 记录是否存在.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <returns></returns>
        public static bool Exists(Expression<Func<SysUser, bool>> expression) {
            return All().Any(expression);
        }
        
        
        /// <summary>
        /// 数据条件分页查询.
        /// </summary>
        /// <param name="expression">条件表达式.</param>
        /// <param name="pageIndex">页次.</param>
        /// <param name="pageSize">页面大小.</param>
        /// <returns></returns>
        public static IList<SysUser> Find(Expression<Func<SysUser, bool>> expression, int? pageIndex, int? pageSize) {
            var repo = GetRepo();
            IQueryable<SysUser> query = repo.Find(expression);
            if (pageIndex.HasValue) {
                query = query.Take(pageSize ?? 10);
                query = query.Skip(((pageIndex ?? 0) - 1) * pageSize ?? 10);
            }
            return query.ToList();
        }

        /// <summary>
        /// 数据条件分页查询.
        /// </summary>
        /// <param name="expression">条件表达式.</param>
        /// <returns></returns>
        public static IList<SysUser> Find(Expression<Func<SysUser, bool>> expression) {
            return Find(expression, null, null);
        }
        #endregion
        
        #region CopyTo
        /// <summary>
        /// 重新复制更新列
        /// </summary>
        /// <param name="to">目标数据实体</param>
        public SysUser CopyTo(SysUser toEntity) {
            Type type = this.GetType();
            List<IColumn> items = type.GetProperties().Join(dirtyColumns.Where(l => !l.IsPrimaryKey), l => l.Name, o => o.PropertyName, (l, o) => o).ToList();
            foreach (IColumn c in items){
                PropertyInfo info = type.GetProperty(c.PropertyName);
                info.SetValue(toEntity, info.GetValue(this, null), null);
            }
            return toEntity;
        }
        #endregion


        
        #region 关联父级
        private SysUser m_FK_SYS_USER_REFER1;
        /// <summary>
        /// FK_SYS_USER_REFER1:用户表.
        /// <remarks>
        /// 外键名称：FK_SYS_USER_REFER1
        /// 主表名称：Sys_User
        /// 外键字段：UserID
        /// </remarks>
        /// </summary>
        [Browsable(false)]
        [XmlIgnore()]
        public SysUser FK_SYS_USER_REFER1{
            get{
                if(m_FK_SYS_USER_REFER1==null&&Context.Instance.AutoLoadRelation){
                    m_FK_SYS_USER_REFER1 = SysUser.FirstOrDefault(this.ParentId);
                }
                return m_FK_SYS_USER_REFER1;
            }
            set{
                m_FK_SYS_USER_REFER1=value;
            }
        }
        private SysCompany m_FK_SYS_USER_REFERENCE_SYS_COMP;
        /// <summary>
        /// FK_SYS_USER_REFERENCE_SYS_COMP:未定义.
        /// <remarks>
        /// 外键名称：FK_SYS_USER_REFERENCE_SYS_COMP
        /// 主表名称：Sys_Company
        /// 外键字段：CompanyCode
        /// </remarks>
        /// </summary>
        [Browsable(false)]
        [XmlIgnore()]
        public SysCompany FK_SYS_USER_REFERENCE_SYS_COMP{
            get{
                if(m_FK_SYS_USER_REFERENCE_SYS_COMP==null&&Context.Instance.AutoLoadRelation){
                    m_FK_SYS_USER_REFERENCE_SYS_COMP = SysCompany.FirstOrDefault(this.CompanyCode);
                }
                return m_FK_SYS_USER_REFERENCE_SYS_COMP;
            }
            set{
                m_FK_SYS_USER_REFERENCE_SYS_COMP=value;
            }
        }
        #endregion
        
        #region 关联子表
        private IList<PnrDetr> lst_FK_PNR_DETR_REFERENCE_SYS_USER;    
        
        /// <summary>
        /// FK_PNR_DETR_REFERENCE_SYS_USER:未定义 .
        /// </summary>
        /// <value>未定义.</value>
        [Browsable(false)]
        [XmlIgnore()]
        public IList<PnrDetr> LSTFK_PNR_DETR_REFERENCE_SYS_USER {
            get {
                if (lst_FK_PNR_DETR_REFERENCE_SYS_USER == null && Context.Instance.AutoLoadRelation) {
                    lst_FK_PNR_DETR_REFERENCE_SYS_USER = PnrDetr.Find(t => t.UserId == this.UserId);
                }
                return lst_FK_PNR_DETR_REFERENCE_SYS_USER;
            }
            set {
                lst_FK_PNR_DETR_REFERENCE_SYS_USER = value;
            }
        }        
        
        /// <summary>
        /// 查询对象：FK_PNR_DETR_REFERENCE_SYS_USER:未定义 .
        /// </summary>
        /// <value>未定义.</value>
        [Browsable(false)]
        public IQueryable< PnrDetr > QURYFK_PNR_DETR_REFERENCE_SYS_USER(Expression<Func<PnrDetr, bool>> predicate)
        {
            return PnrDetr.All().Where(predicate);
        }
        
        private IList<PnrRequire> lst_FK_PNR_REQU_REFERENCE_SYS_USER;    
        
        /// <summary>
        /// FK_PNR_REQU_REFERENCE_SYS_USER:占座PNR库 .
        /// </summary>
        /// <value>占座PNR库.</value>
        [Browsable(false)]
        [XmlIgnore()]
        public IList<PnrRequire> LSTFK_PNR_REQU_REFERENCE_SYS_USER {
            get {
                if (lst_FK_PNR_REQU_REFERENCE_SYS_USER == null && Context.Instance.AutoLoadRelation) {
                    lst_FK_PNR_REQU_REFERENCE_SYS_USER = PnrRequire.Find(t => t.UserId == this.UserId);
                }
                return lst_FK_PNR_REQU_REFERENCE_SYS_USER;
            }
            set {
                lst_FK_PNR_REQU_REFERENCE_SYS_USER = value;
            }
        }        
        
        /// <summary>
        /// 查询对象：FK_PNR_REQU_REFERENCE_SYS_USER:占座PNR库 .
        /// </summary>
        /// <value>占座PNR库.</value>
        [Browsable(false)]
        public IQueryable< PnrRequire > QURYFK_PNR_REQU_REFERENCE_SYS_USER(Expression<Func<PnrRequire, bool>> predicate)
        {
            return PnrRequire.All().Where(predicate);
        }
        
        private IList<SysUser> lst_FK_SYS_USER_REFER1;    
        
        /// <summary>
        /// FK_SYS_USER_REFER1:用户表 .
        /// </summary>
        /// <value>用户表.</value>
        [Browsable(false)]
        [XmlIgnore()]
        public IList<SysUser> LSTFK_SYS_USER_REFER1 {
            get {
                if (lst_FK_SYS_USER_REFER1 == null && Context.Instance.AutoLoadRelation) {
                    lst_FK_SYS_USER_REFER1 = SysUser.Find(t => t.ParentId == this.UserId);
                }
                return lst_FK_SYS_USER_REFER1;
            }
            set {
                lst_FK_SYS_USER_REFER1 = value;
            }
        }        
        
        /// <summary>
        /// 查询对象：FK_SYS_USER_REFER1:用户表 .
        /// </summary>
        /// <value>用户表.</value>
        [Browsable(false)]
        public IQueryable< SysUser > QURYFK_SYS_USER_REFER1(Expression<Func<SysUser, bool>> predicate)
        {
            return SysUser.All().Where(predicate);
        }
        
        private IList<SysUserAuthority> lst_FK_SYS_USER_REFERE2;    
        
        /// <summary>
        /// FK_SYS_USER_REFERE2:用户权限关联表 .
        /// </summary>
        /// <value>用户权限关联表.</value>
        [Browsable(false)]
        [XmlIgnore()]
        public IList<SysUserAuthority> LSTFK_SYS_USER_REFERE2 {
            get {
                if (lst_FK_SYS_USER_REFERE2 == null && Context.Instance.AutoLoadRelation) {
                    lst_FK_SYS_USER_REFERE2 = SysUserAuthority.Find(t => t.UserId == this.UserId);
                }
                return lst_FK_SYS_USER_REFERE2;
            }
            set {
                lst_FK_SYS_USER_REFERE2 = value;
            }
        }        
        
        /// <summary>
        /// 查询对象：FK_SYS_USER_REFERE2:用户权限关联表 .
        /// </summary>
        /// <value>用户权限关联表.</value>
        [Browsable(false)]
        public IQueryable< SysUserAuthority > QURYFK_SYS_USER_REFERE2(Expression<Func<SysUserAuthority, bool>> predicate)
        {
            return SysUserAuthority.All().Where(predicate);
        }
        
        #endregion
    }
} 



